familypediawikiaorg-20200214-history
Help:Inline queries/Introduction and default text
Subpages of the main Help page: * 1 /Introduction to "hash"ask * 2 /The "hash"show parser function * 3 /Standard parameters for inline queries **3.1 /Result limits and links to further results **3.2 /Introduction and default text **3.3 /Sorting results **3.4 /Configuring labels or table headers **3.5 /Changing the first result column * 4 /Result formats * 5 /Exporting query results: RSS, etc. * 6 /Using templates for custom formatting If no articles satisfy the conditions of a query, nothing is shown. This is sometimes a useful behaviour, but often certain texts should be shown or not shown depending on whether the query has results or not. For example, one may want the query to show an output of the following form: Upcoming conferences: ISWC2008, IJCAI2007, … where the list of conferences is generated by a suitable query. If the query (for whatever reason) would not return any results, the page would look as follows Upcoming conferences: which is not desirable. Two parameters exist to prevent this. * default: this parameter can be set to a default text that should be returned when no results are obtained. In the above example, one would probably write something like Upcoming conferences: : so that, if no result is obtained, the article will display Upcoming conferences: none * intro: this parameter specifies a text that should be prepended to the output of a query, but only if one or more results exist. In the above example, one could write : so that, if no result is obtained, nothing will be printed at all. Note that we use «_» to encode the final space. This is needed for initial and final spaces in any parameter, since those are otherwise removed internally (this is always the case in MediaWiki and is not specific to SMW). Both of the above solutions will show the intended output if results are found. It is also possible to combine both parameters if desired. The parameters can also include MediaWiki markup, such as links or templates, as long as this does not confuse MediaWiki in recognising the #ask function. Also note that if the set of pages selected in a query is empty, no header row or blank line, not even any blank space, is produced. This can also be useful to «hide» queries that are not applicable. However, it is not recommended to insert great amounts of queries into every page, based on the assumption that this can do no harm since no output is generated. Indeed, answering queries requires much computational resources and should not be done without a purpose. Using default texts for queries is also a good habit in general, since it may happen that a query will no longer have any results in some future, e.g. due to changes in the way the wiki organises its data. Such queries that once worked properly may be forgotten so that nobody notices the query on a page labouring to display nothing. Category:Semantic MediaWiki